package twl.global.widget;


import castledefense.util.Log;
import de.matthiasmann.twl.Alignment;
import de.matthiasmann.twl.AnimationState;
import de.matthiasmann.twl.Label;
import de.matthiasmann.twl.ParameterMap;
import de.matthiasmann.twl.ThemeInfo;
import de.matthiasmann.twl.renderer.AnimationState.StateKey;

public class LabelFonts extends Label{
	
	public static final StateKey STATE_BLACK = StateKey.get("black");
	public static final StateKey STATE_BLUE = StateKey.get("blue");
	public static final StateKey STATE_RED = StateKey.get("red");
	
	private ParameterMap fontMap = null;
	private String fontName = null;
	
	private Alignment align = null;
	
	public LabelFonts(){
		super();
	}
	
	public LabelFonts(String text){
		super(text);
	}
	
	public void setFont(String fontName){
		this.fontName = fontName;
		if(fontMap != null && fontName != null){
			setFont(fontMap.getFont(fontName));
		}
	}
	
	@Override
	public void setAlignment(Alignment alignment){
		if(align == null && alignment != null){
			align = alignment;
			super.setAlignment(alignment);
		}
	}
	
	public void setColor(StateKey stateKey){
		AnimationState as = getAnimationState();
		as.setAnimationState(STATE_BLACK, false);
		as.setAnimationState(STATE_BLUE, false);
		as.setAnimationState(STATE_RED, false);
		as.setAnimationState(stateKey, true);
	}
	
	@Override
	protected void applyThemeTextWidget(ThemeInfo themeInfo) {
		fontMap = themeInfo.getParameterMap("fonts");
		if(fontName != null){
			setFont(fontMap.getFont(fontName));
		}else{
			setFont(themeInfo.getFont("font"));
		}
        setAlignment(themeInfo.getParameter("textAlignment", Alignment.TOPLEFT));
    }

}
